
#include<iostream>
#include <time.h>
#include <cstdlib>
#include <unistd.h>
#include<pthread.h>


void *consumer(void *args){
    pthread_detach(pthread_self());
    while(true){
        sleep(1);
        std::cout<<"hello" <<std::endl;
    }
}

void *producter(void *args){
    pthread_detach(pthread_self());
    while(true){
        sleep(2);
        std::cout<<"xx" <<std::endl;
    }
}

int main(){

    pthread_t c,p;
    pthread_create(&c, nullptr, consumer, nullptr);
    pthread_create(&p, nullptr, producter, nullptr);

    sleep(10);//线程的创建会比主线程慢一些，需要在主线程等待子线程执行自定义函数
    return 0;
}
